//
//  MyBankViewController.m
//  HengYouCai
//
//  Created by ycgwl on 2017/5/1.
//  Copyright © 2017年 lwj. All rights reserved.
//

#import "MyBankViewController.h"
#import "BannerWebViewVC.h"
@interface MyBankViewController ()

/**
 银行名字
 */
@property (weak, nonatomic) IBOutlet UILabel *bankName;

/**
 银行卡号
 */
@property (weak, nonatomic) IBOutlet UILabel *kahao;

/**
 银行图标
 */
@property (weak, nonatomic) IBOutlet UIImageView *bankIcon;

/**
 单笔限额
 */
@property (weak, nonatomic) IBOutlet UILabel *bankSingleLimit;

/**
 每日限额
 */
@property (weak, nonatomic) IBOutlet UILabel *bankDailyLimit;

/**
 换卡帮助
 */
@property (weak, nonatomic) IBOutlet UIButton *helpBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imgToTop;

/**
 提示
 */
@property (weak, nonatomic) IBOutlet UILabel *callLab;

/**
 带阴影的view
 */
@property (weak, nonatomic) IBOutlet UIView *shadowView;
@end

@implementation MyBankViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的银行卡";
    __weak typeof(self) weakSelf = self;
    
    /**
     获取银行卡信息
     
     */
    [HYCNetService accountActionMyBankOnSuccess:^(NSDictionary *dictResult) {
        //
        [weakSelf setMyBankWithDic:dictResult];
    } andFailed:^(NSInteger code, NSString *errorMsg) {
        //
        [self.view showHUDFailTips:errorMsg hideDelay:kHUDHideDelay];
    }];
    // 小屏幕上布局问题
    if (f_Device_w < 321) {
        _imgToTop.constant = 30;
        
    } else {
        // Fallback on earlier versions
        _imgToTop.constant = 65;
        
    }
    _shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
    _shadowView.layer.shadowOffset = CGSizeMake(0, 2);//设置阴影的偏移量
    // 打电话提示内容
    NSString *tell = [WLFileManager readUserDataForKey:kPhone];
    _callLab.lineBreakMode = NSLineBreakByCharWrapping;
    _callLab.attributedText = [NSString stringWithStrArray:@[@"为了保障您的账户安全，只支持绑定一张银行卡进行充值与提现如有疑问，请咨询客服 ",tell] colorArray:@[Normal_GrayColor,[UIColor colorWithHexString:@"#599DFB"]]];
}

/**
 页面赋值
 */
- (void)setMyBankWithDic:(NSDictionary *)dic
{
    _bankName.text = dic[@"bankName"];
    NSString *bankStr = [NSString stringJsonValue:dic[@"bankCode"]];
    _kahao.text = bankStr;
    _bankDailyLimit.text = [NSString stringWithMoneyNoPointNOYuan:dic[@"bankDailyLimit"]];;
    _bankSingleLimit.text = [NSString stringWithMoneyNoPointNOYuan:dic[@"bankSingleLimit"]];;
    
    [_bankIcon sd_setImageWithURL:[NSURL URLWithString:dic[@"bankImg"]]];
    
    BannerWebViewVC *bannerWeb = [[BannerWebViewVC alloc] initWithUrlStr:dic[@"bankChangeRoleURL"] title:@"换卡规则"];
    // 切换银行卡 帮助
    [[_helpBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [self.navigationController pushViewController:bannerWeb animated:YES];
    }];
}
- (IBAction)call:(id)sender {
    // 这样就不会出现有的手机上不弹框提示就 直接打电话
    NSString *tell = [WLFileManager readUserDataForKey:kPhone];
    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", tell];
    /// 防止iOS 10及其之后，拨打电话系统弹出框延迟出现
    dispatch_async(dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    });
    
    
}

@end

